<?php
	//$this->firephp->log($post,'post');
	//$this->firephp->log($post['extras'],'post["extras"]');
	//$this->firephp->log($offer,'offer');
	//$this->firephp->log($school,'school');
	//$this->firephp->log($schoolId,'schoolId');
	//$this->firephp->log($extras,'extras');
	
	// set data about client in the session
	$this->session->set_userdata('newClient',$post);
	$this->session->set_userdata('price',
		array(
			'total' 		=>$total, 
			'pay2hotel'		=>$pay2hotel, 
			'hotelPayment'	=>$hotelPayment, 
			'transportPrice'=>$transportPrice
		)
	);
?>


<div class="container_16">
	<div class="grid_16 headerInfo">Efectuar reserva no seguinte cliente: </div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">Nome: </div>
	<div class="grid_6 info"><?php echo $post['name']; ?></div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">Morada: </div>
	<div class="grid_6 info"><?php echo $post['address']; ?></div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">eMail:</div>
	<div class="grid_3 info"><?php echo $post['email']; ?></div>
	<div class="grid_2 label">telefone:</div>
	<div class="grid_2 info"><?php echo $post['phone']; ?></div>
	<div class="grid_3 label">data de nascimento:</div>
	<div class="grid_2 info"><?php echo $post['birthday']; ?></div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">altura (cm):</div>
	<div class="grid_3 info"><?php echo $post['height'].' cm'; ?></div>
	<div class="grid_2 label">Peso (cm):</div>
	<div class="grid_2 info"><?php echo $post['weight'].' Kg'; ?></div>
	<div class="grid_3 label">Nacionalidade</div>
	<div class="grid_3 info"><?php echo $post['nationality']; ?></div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">Observações:</div>
	<div class="grid_6 info"><?php echo $post['info']; ?></div>
	<div class="clear"></div>
	
	<div class="grid_16 headerInfo">Informação da Oferta</div>
	<div class="grid_2 prefix_1 label">Nome: </div>
	<div class="grid_6 info"><?php echo $offer->offerName; ?></div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">Nivel: </div>
	<div class="grid_3 info"><?php echo $offer->offerLevel; ?></div>
	<div class="grid_2 label">Preço: </div>
	<div class="grid_2 info"><?php echo $offer->offerPrice.' €'; ?></div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">Descrição: </div>
	<div class="grid_6 info"><?php echo $offer->offerDescription; ?></div>
	<div class="clear"></div>
	
	<div class="grid_16 headerInfo">Informação da Escola</div>
	<div class="grid_2 prefix_1 label">Nome: </div>
	<div class="grid_6 info"><?php echo $school->company; ?></div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">Morada: </div>
	<div class="grid_6 info"><?php echo $school->address; ?></div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">eMail:</div>
	<div class="grid_3 info"><?php echo $school->email; ?></div>
	<div class="grid_2 label">telefone:</div>
	<div class="grid_2 info"><?php echo $school->phone; ?></div>
	<div class="clear"></div>
	
	<div class="grid_16 headerInfo">Extras:</div>
	<?php 
	if (empty($extras)) { ?>
		<div class="grid_6 info">... sem ofertas</div>
		<div class="clear"></div>
		<?php 
	}
	else {
		foreach ($extras as $key => $value) { ?>	
		
			<div class="grid_2 prefix_1 label">Extra: </div>
			<div class="grid_1 info"><?php echo $key+1; ?></div>
			<div class="grid_2 prefix_1 label">Nome: </div>
			<div class="grid_3 info"><?php echo $value->name; ?></div>
			<div class="grid_2 prefix_1 label">Preco: </div>
			<div class="grid_3 info"><?php echo $value->price; ?></div>
			<div class="clear"></div>
			<?php
		}
  	} ?>
  	
  	<?php 
  	if ($post['transport'] == 'yes') {?>
		<div class="grid_6 info">com transporte: <?php echo $transportPrice.' €';?></div>
		<?php 
  	}
  	else { ?>
		<div class="grid_6 info">sem transporte</div>
		<?php 
  	} ?>
  	
	<div class="clear"></div>
	
	<div class="grid_16 headerInfo">Total:</div>
	<div class="grid_2 prefix_1 label">Preco Total:</div>
	<div class="grid_2 info"><?php echo $total.' €'; ?></div>
	<div class="clear"></div>
	<div class="grid_2 prefix_1 label">Entrada:</div>
	<div class="grid_2 info"><?php echo $pay2hotel.' € ( '.$hotelPayment.' % )'; ?></div>
</div>

<div class="clear"></div>

<!--
<div class="container_16">
	<div class="grid_3 prefix_11">
		<button id="reserveButton">Reservar</button>
	</div>
	<div class="grid_3 prefix_1">
		<button id="cancelButton">Cancelar</button>
	</div>
</div>
-->

<button id="cancelButton">Cancelar</button>
<button id="printButton">Imprimir</button>
<button id="reserveButton">Reservar</button>

<div class="clear"></div>

<!-- Others dialogs -->
<div id="noClientSelected" 		title="Alerta" 	class="dialog">nenhum cliente selecionado</div>
<div id="genericAlert" 			title="Alerta" 	class="dialog"> ... </div>
<!-- ******* -->

<script>

	
	$(document).ready(function() {
		
		var reserveInfo = {
			offerId:	<?php echo $post['offerId'];	?>,
			classId:	<?php echo $post['classId'];	?>,
			clientId:	<?php echo $post['clientId'];	?>,
			userId:		<?php echo $userId;				?>,
			extras:		'<?php echo $post['extras'];	?>'
		};
		
		//console.log('reserveInfo', reserveInfo);
		
		buttonEvents(reserveInfo);
	});



	
	function buttonEvents(reserveInfo) {
		
		var reserveButton 	= $('#reserveButton'); 
		var cancelButton 	= $('#cancelButton'); 
		var printButton 	= $('#printButton'); 
		
		reserveButton.button();
		cancelButton.button();
		printButton.button();
		
		reserveButton.click(function() {

			// confirmation ...
			var alertDialog = $('#genericAlert');
			
			alertDialog.html('tem a certeza de que pretende fazer esta reserva?');
			
			alertDialog.dialog({
				width:		350,
				height:		150,
				show: 		'fade',
				hide: 		'fade',
				buttons: {
					"Sim": 	function() {
						saveReservation(reserveInfo);
						$(this).dialog("close");
					},
					"Não": 	function() {
						$(this).dialog("close");
					}
				}
			});
		});
		
		cancelButton.click(function() {
			window.location.href = window.ajaxUrl + '/offers';
		});
		
		printButton.click(function() {
			window.print();
		});
		
	}




	/**
	 * Function to store the reservatin data in the server
	 * The new client info should also be passed
	 */
	function saveReservation(reserveInfo) {

		$.ajax({
			url:		window.ajaxUrl + '/createReservationAction',
			type:		'POST',		// type of request to make
			async:		true,		// asynchronous/synchronous request
			dataType:	"json",		// type of data returned from server
			
			// data to send
			data:					
			{
				offerId:		reserveInfo.offerId,
				classId:		reserveInfo.classId,
				clientId:		reserveInfo.clientId,
				userId:			reserveInfo.userId,
				extras:			reserveInfo.extras
			},

			// request was successful ... 'data' is received from server
			success: 	function(data, textStatus, jqXHR) {
				if(data) {
					var alertDialog = $('#genericAlert');
					alertDialog.html(data.msg);
					alertDialog.dialog({
						width:		350,
						height:		150,
						show: 		'fade',
						hide: 		'fade',
						buttons: {
							"Ok": 		
							function() {
								window.location.href = window.ajaxUrl + '/offers';
								$(this).dialog("close");
							}
						}
					});
					
					//alert(data.msg);
					//console.log(data.msg);
				}
			},

			// something went wrong ...
			error:		function(jqXHR, textStatus, errorThrown) {	
				
			},
			
			// code to run regardless of success or failure
			complete: function(xhr, status) {
				
			}
		});
	}
	

</script>









<!--  
<div id="clientData" class="">
	<div class="row">
		<div class="label1">Nome: </div>
		<div class="info4">adriano teixeira</div>
	</div>
	<div class="label1">Morada:</div>
	<div class="info4">Exemplo morada</div>
	
	<div class="label1">eMail:</div>
	<div class="info3">mail@mail.com</div>
	
	<div class="label1">Telefone: </div>
	<div class="info3">9999999</div>
	
	<div class="label3">Data de Nascimento: </div>
	<div class="info1">20/12/1990</div>
	
	<div class="label2">Nacionalidade:</div>
	<div class="info3">portuguesa</div>
	
	
	
	<div>Altura (cm): </div>
	
	<div>Peso (kg): </div>
	
	<div>Sexo: </div>
	
	
	<div>Observações: </div>
	
	<div>Extras Incluidos: </div>
	
	<div>Extras adicionados: </div>
	
</div>

-->
